<!DOCTYPE html>
<html style="width:100%;height:100%;">
<head lang="en">
    <meta charset="UTF-8">
    <title>活动记录列表</title>
    <link type="text/css" rel="stylesheet" href="/resources/easyui/themes/default/easyui.css">
    <link type="text/css" rel="stylesheet" href="/resources/easyui/themes/color.css">
    <link type="text/css" rel="stylesheet" href="/resources/easyui/themes/icon.css">
    <link type="text/css" rel="stylesheet" href="/resources/css/yidong.css">
    <script type="text/javascript" src="/resources/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/resources/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/resources/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/resources/easyui/plugin/jquery.cookie.js"></script>
    <script type="text/javascript" src="/resources/js/Util.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            var pageSize = $.cookie("pageSize");
            if(!pageSize) {
                $.cookie("pageSize", 10, {expires:1});
            }
            loadList($.cookie("pageSize"), 1);
            var pager = $('#theList').datagrid('getPager');
            if(pager){
                $(pager).pagination({
                    onSelectPage:function(pageNumber, pageSize){
                        loadList(pageSize, pageNumber, null, getPostData());
                    },
                    onRefresh:function(pageNumber, pageSize){
                        loadList(pageSize, pageNumber, null, getPostData());
                    },
                    onChangePageSize:function(pageSize){
                        $.cookie("pageSize", pageSize, {expires:1});
                        loadList(pageSize, 1, null, getPostData());
                    }
                })
            }
        });

        function loadList(pageSize, pageNo, successFun, condition) {
            var data = 'pageSize='+pageSize+'&pageNo='+pageNo;
            if(condition) {
                data = data + '&' + condition;
            }
            restClient('/rest/playGame/list', function(data){
                $('#theList').datagrid("loadData", data);
                if(successFun) successFun();
            }, data);
        }

        function searchList() {
            loadList($.cookie("pageSize"), 1, null, getPostData());
        }

        function getPostData() {
            var postData = $('#searchForm').serialize();
            var start = $('#startDate').datebox('getText');
            var end = $('#endDate').datebox('getText');
            if (start) {
                postData += '&startDate=' + start;
            }
            if (end) {
                postData += '&endDate=' + end;
            }

            return postData;
        }

        function formatResult(value,row,index){
            if(row.result != null) {
                if(row.result){
                    return "<a href='"+row.result+"' target='_blank'>"
                    + "<img width='50px' height='50px' src='"+ row.result + "'/>"
                    + "</a>";
                } else {
                    return row.result;
                }
            }
        }

        function myformatter(date){
            var y = date.getFullYear();
            var m = date.getMonth()+1;
            var d = date.getDate();
            return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
        }

        function formatDateTime(value, row, index) {
            if(row.finishTime) {
                return new Date(row.finishTime).Format("yyyy-MM-dd hh:mm:ss");
            }
        }

        function formatPrize(value, row, index) {
            if (row.prize) {
                if (row.prize == 1) {
                    return '已审核';
                }
            } else {
                return '未审核';
            }
        }

        function formatId(value,row,index){
            if(row.id != null) {
                if(row.id){
                    return '<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="auditOne(' + row.id + ')">审核</a>' +
                            '&nbsp;&nbsp;&nbsp;' +
                            '<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="forceAuditOne(' + row.id + ')">强制审核</a>' +
                            '&nbsp;&nbsp;&nbsp;' +
                            '<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="deleteOne(' + row.id + ')">删除</a>';
                } else {
                    return row.id;
                }
            }
        }

    </script>
</head>
<body onload="isLogon();" style="width:100%;height:100%;margin: 0;">
<table id="theList" class="easyui-datagrid" style="width:100%;height:100%;"
       toolbar="#toolbar" pagination="true"
       data-options="pageList:[10,15,20],pageSize:$.cookie('pageSize') ? $.cookie('pageSize') : 10"
       rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
    <tr>
        <th field="appId" width="80">AppId</th>
        <th field="openId" width="80">OpenId</th>
        <th field="gameName" width="80">活动名字</th>
        <th field="tel" width="40">手机号</th>
        <th field="result" width="60" data-options="formatter:formatResult">截图</th>
        <th field="finishTime" width="70" data-options="formatter:formatDateTime">时间</th>
        <th field="prize" width="40" data-options="formatter:formatPrize">状态</th>
        <th field="id" width="120" data-options="formatter:formatId">操作</th>
    </tr>
    </thead>
</table>

<div id="toolbar">
    <form id="searchForm">
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        时间: <input id="startDate" class="easyui-datebox" data-options="editable:false,formatter:myformatter">
        至 <input id="endDate" class="easyui-datebox" data-options="editable:false,formatter:myformatter">
        &nbsp;&nbsp;&nbsp;
        状态:
        <select class="easyui-combobox" name="prize" data-options="editable:false">
            <option value="1000">全部</option>
            <option value="1">已审核</option>
            <option value="0">未审核</option>
        </select>
        &nbsp;&nbsp;&nbsp;
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="searchList()">搜索</a>
    </form>
</div>

<script type="text/javascript">
    function auditOne(id) {
        $.messager.confirm('确认','确认要审核通过么?',function(r){
            if (r){
                restClient('/rest/playGame/audit/'+id, function(result){
                    if (result.success){
                        loadList($.cookie("pageSize"), 1, function(){
                            $.messager.show({
                                title: '温馨提醒',
                                msg: "审核成功"
                            });
                        }, getPostData());
                    } else {
                        $.messager.show({
                            title: '温馨提醒',
                            msg: result.msg ? result.msg : result.message
                        });
                    }
                }, getPostData());
            }
        });
    }

    function forceAuditOne(id) {
        $.messager.confirm('确认','确认要强制审核通过么?',function(r){
            if (r){
                restClient('/rest/playGame/forceAudit/'+id, function(result){
                    if (result.success){
                        loadList($.cookie("pageSize"), 1, function(){
                            $.messager.show({
                                title: '温馨提醒',
                                msg: "强制审核成功"
                            });
                        }, getPostData());
                    } else {
                        $.messager.show({
                            title: '温馨提醒',
                            msg: result.msg ? result.msg : result.message
                        });
                    }
                }, getPostData());
            }
        });
    }

    function deleteOne(id) {
        $.messager.confirm('确认','确认要删除么?',function(r){
            if (r){
                restClient('/rest/playGame/delete/'+id, function(result){
                    if (result.success){
                        loadList($.cookie("pageSize"), 1, function(){
                            $.messager.show({
                                title: '温馨提醒',
                                msg: "删除成功"
                            });
                        }, getPostData());
                    } else {
                        $.messager.show({
                            title: '温馨提醒',
                            msg: result.msg ? result.msg : result.message
                        });
                    }
                });
            }
        });
    }
</script>
</body>
</html>